package com.xie.smfs.event;

import com.xie.smfs.damage.ModDamageSources;
import com.xie.smfs.registry.ModEffects;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;

public class ModEvents {
    public static void registerEvents() {
        ServerLivingEntityEvents.ALLOW_DAMAGE.register((entity, source, amount) -> {
            // 直接使用 entity 作为 LivingEntity，因为事件回调的参数已经是 LivingEntity
            if (source.getAttacker() instanceof PlayerEntity player) {
                if (player.hasStatusEffect(ModEffects.SPIRIT_SURGE)) {
                    // 使用正确的伤害源创建方式
                    DamageSource ghostDamage = ModDamageSources.ghost(entity.getWorld());
                    entity.damage(ghostDamage, 5.0F);
                }
            }
            return true; // 允许原始伤害继续处理
        });
    }
}